<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03_upload.html</title>
  <style>
    #div { width: 600px; height: 300px; border: 2px solid black;
      background-color: aliceblue; font-size: 46px;
      text-align: center; line-height: 300px; font-weight: bold;
    }
  </style>
</head>
<body>
  <div id="div">
    将文件拖入此处上传
  </div>  
  <input type="file" id="file">
  <script src="./axios.min.js"></script>
  <script>
    let file=document.getElementById("file")
    file.addEventListener('change',(event)=>{
      console.log(file.files.item(0).getWebkitRelativePath);
    })
    div.addEventListener("dragover", (e)=>{
      e.preventDefault(); // 保证drop事件的产生
    });
    div.addEventListener('drop', (e)=>{
      // 接收拖拽进来的文件信息
      let files = e.dataTransfer.files;
      console.log(files);
      // 将files中的文件，上传到服务端
      let formData = new FormData();
      formData.append('uploadFile', files[0]);
      axios.post('http://localhost:3000/upload', formData)
      e.stopPropagation();
      e.preventDefault();   // 解决firefox的兼容问题
    })
  </script>
</body>
</html>



